﻿using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.ModLoader;

namespace Terraria.GameInput
{
	// Token: 0x020003AF RID: 943
	public class KeyConfiguration
	{
		// Token: 0x17000236 RID: 566
		// (get) Token: 0x060020F8 RID: 8440 RVA: 0x004608DC File Offset: 0x0045EADC
		public bool DoGrappleAndInteractShareTheSameKey
		{
			get
			{
				return this.KeyStatus["Grapple"].Count > 0 && this.KeyStatus["MouseRight"].Count > 0 && this.KeyStatus["MouseRight"].Contains(this.KeyStatus["Grapple"][0]);
			}
		}

		// Token: 0x060020F9 RID: 8441 RVA: 0x00460948 File Offset: 0x0045EB48
		public void SetupKeys()
		{
			this.KeyStatus.Clear();
			foreach (string key in PlayerInput.KnownTriggers)
			{
				this.KeyStatus.Add(key, new List<string>());
			}
			foreach (KeyValuePair<string, ModHotKey> keyValuePair in ModLoader.modHotKeys)
			{
				this.KeyStatus.Add(keyValuePair.Value.displayName, new List<string>());
			}
		}

		// Token: 0x060020FA RID: 8442 RVA: 0x00460A00 File Offset: 0x0045EC00
		public void Processkey(TriggersSet set, string newKey)
		{
			foreach (KeyValuePair<string, List<string>> keyValuePair in this.KeyStatus)
			{
				if (keyValuePair.Value.Contains(newKey))
				{
					set.KeyStatus[keyValuePair.Key] = true;
				}
			}
			if (set.Up || set.Down || set.Left || set.Right || set.HotbarPlus || set.HotbarMinus || ((Main.gameMenu || Main.ingameOptionsWindow) && (set.MenuUp || set.MenuDown || set.MenuLeft || set.MenuRight)))
			{
				set.UsedMovementKey = true;
			}
		}

		// Token: 0x060020FB RID: 8443 RVA: 0x00460AD4 File Offset: 0x0045ECD4
		public void CopyKeyState(TriggersSet oldSet, TriggersSet newSet, string newKey)
		{
			foreach (KeyValuePair<string, List<string>> keyValuePair in this.KeyStatus)
			{
				if (keyValuePair.Value.Contains(newKey))
				{
					newSet.KeyStatus[keyValuePair.Key] = oldSet.KeyStatus[keyValuePair.Key];
				}
			}
		}

		// Token: 0x060020FC RID: 8444 RVA: 0x00460B54 File Offset: 0x0045ED54
		public void ReadPreferences(Dictionary<string, List<string>> dict)
		{
			this.UnloadedModKeyStatus = new Dictionary<string, List<string>>();
			foreach (KeyValuePair<string, List<string>> keyValuePair in dict)
			{
				if (this.KeyStatus.ContainsKey(keyValuePair.Key))
				{
					this.KeyStatus[keyValuePair.Key].Clear();
					using (List<string>.Enumerator enumerator2 = keyValuePair.Value.GetEnumerator())
					{
						while (enumerator2.MoveNext())
						{
							string item = enumerator2.Current;
							this.KeyStatus[keyValuePair.Key].Add(item);
						}
						continue;
					}
				}
				if (keyValuePair.Key.Contains(":"))
				{
					this.UnloadedModKeyStatus[keyValuePair.Key] = new List<string>();
					foreach (string item2 in keyValuePair.Value)
					{
						this.UnloadedModKeyStatus[keyValuePair.Key].Add(item2);
					}
				}
			}
		}

		// Token: 0x060020FD RID: 8445 RVA: 0x00460CD4 File Offset: 0x0045EED4
		public Dictionary<string, List<string>> WritePreferences()
		{
			Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
			foreach (KeyValuePair<string, List<string>> keyValuePair in this.KeyStatus)
			{
				if (keyValuePair.Value.Count > 0)
				{
					dictionary.Add(keyValuePair.Key, keyValuePair.Value.ToList<string>());
				}
			}
			foreach (KeyValuePair<string, List<string>> keyValuePair2 in this.UnloadedModKeyStatus)
			{
				if (keyValuePair2.Value.Count > 0)
				{
					dictionary.Add(keyValuePair2.Key, keyValuePair2.Value.ToList<string>());
				}
			}
			if (!dictionary.ContainsKey("MouseLeft") || dictionary["MouseLeft"].Count == 0)
			{
				dictionary.Add("MouseLeft", new List<string>
				{
					"Mouse1"
				});
			}
			if (!dictionary.ContainsKey("Inventory") || dictionary["Inventory"].Count == 0)
			{
				dictionary.Add("Inventory", new List<string>
				{
					"Escape"
				});
			}
			return dictionary;
		}

		// Token: 0x04003D7E RID: 15742
		public Dictionary<string, List<string>> KeyStatus = new Dictionary<string, List<string>>();

		// Token: 0x04003D7F RID: 15743
		public Dictionary<string, List<string>> UnloadedModKeyStatus = new Dictionary<string, List<string>>();
	}
}
